package com.ec.cr.service.impl;


import com.ec.api.domain.po.MedicineRecord;
import com.ec.cr.domain.vo.MedicineRecordVO;
import com.ec.cr.domain.vo.StatItemVO;
import com.ec.cr.mapper.MedicineRecordMapper;
import com.ec.cr.service.MedicineRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MedicineRecordServiceImpl implements MedicineRecordService {

    @Autowired
    private MedicineRecordMapper medicineRecordMapper;

    @Override
    public List<MedicineRecordVO> findRecords(String elderlyName, String drugName) {
        return medicineRecordMapper.findRecords(elderlyName, drugName);
    }

    @Override
    public List<MedicineRecordVO> findPageRecords(String elderlyName, String drugName, int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return medicineRecordMapper.selectPageRecords(elderlyName, drugName, offset, pageSize);
    }

    @Override
    public long countRecords(String elderlyName, String drugName) {
        return medicineRecordMapper.countRecords(elderlyName, drugName);
    }

    @Override
    public List<Map<String, Object>> getElderlySimpleList() {
        return medicineRecordMapper.selectElderlySimpleList();
    }



    @Override
    public void addRecord(MedicineRecord record) {
        medicineRecordMapper.insertRecord(record);
    }

    @Override
    public void updateRecord(MedicineRecord record) {
        medicineRecordMapper.updateRecord(record);
    }

    @Override
    public void deleteRecord(Integer id) {
        medicineRecordMapper.deleteRecord(id);
    }

    // ======= 新增 =======
    @Override
    public List<StatItemVO> countByMonth(Long elderlyUserId) {
        return medicineRecordMapper.countByMonth(elderlyUserId);
    }

    @Override
    public List<StatItemVO> sumByDrug(Long elderlyUserId) {
        return medicineRecordMapper.sumByDrug(elderlyUserId);
    }

    @Override
    public List<StatItemVO> sumCostByDay(Long elderlyUserId) {
        return medicineRecordMapper.sumCostByDay(elderlyUserId);
    }

    @Override
    public List<MedicineRecordVO> findPageRecordsByUserId(Long elderlyUserId, String drugName, int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return medicineRecordMapper.selectPageRecordsByUserId(elderlyUserId, drugName, offset, pageSize);
    }

    @Override
    public long countRecordsByUserId(Long elderlyUserId, String drugName) {
        return medicineRecordMapper.countRecordsByUserId(elderlyUserId, drugName);
    }

}
